<?php
class neoobjectneoindex extends XoopsObject{
	function neoobjectneoindex (){
	$this->XoopsObject();
	$this->initVar('obj_id', XOBJ_DTYPE_INT, 0, false,4);								
	$this->initVar('city_id', XOBJ_DTYPE_INT, 0, false,4);			
	$this->initVar('country_id', XOBJ_DTYPE_INT, 0, false,4);			
	$this->initVar('region_id', XOBJ_DTYPE_INT, 0, false,4);					
	$this->initVar('prop_id', XOBJ_DTYPE_INT, 0, false,4);						
	$this->initVar('hits', XOBJ_DTYPE_INT,0, false,4);						
	$this->initVar('comments', XOBJ_DTYPE_INT,  0, false,4);							
						
	}
}

class neoobjectneoindexHandler extends XoopsObjectHandler {
	var $table="neoobjectneoindex";
	  function &create($isNew = true)
    {
        $item = new neoobjectneoindex();
        if ($isNew) {
            $item->setNew();
        }
        return $item;
    }
	function createtable(&$item){
		$sql = "DROP TABLE ".$this->db->prefix($this->table)." ";
#		echo $sql;
		$this->db->queryF($sql);
		echo $this->db->Error();
		$sqltxt = "CREATE TABLE ".$this->db->prefix($this->table)." (";	
		$fields = array();
		foreach ($item->vars as $key=>$arrval){
			
			switch($arrval['data_type']){
			case XOBJ_DTYPE_INT:
			 		$fields[] =  "$key INT($arrval[maxlength]) NOT NULL";
			}
			
			
		}
		$sqltxt .= join(",\n",$fields);
		$sqltxt .= ")";
		echo $sqltxt;
		$this->db->queryF($sqltxt);
		echo $this->db->Error();
	}
	function insert(&$item){
	  if (!$item->cleanVars()) {
            return false;
        }
	 $fields = array();
	 $values = array();
	  foreach ($item->cleanVars as $k => $v) {
       $fields[]=$k;            
	  switch($item->vars[$k]['data_type']){
	 
	  case XOBJ_DTYPE_INT:
			$values[] =  $v;
	  }
	 
	 }
	 $sqltxt = "INSERT INTO ".$this->db->prefix($this->table)." (".join(',',$fields).") VALUES (".join(",",$values).")";
	 $this->db->queryF($sqltxt);
	 echo $this->db->Error();
	}
	
}

?>